/**
 * 
 */
package niuke;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class 字符串价值 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String string = scanner.nextLine();
		int k = scanner.nextInt();
		scanner.close();
		int n = string.length();
		int[] freq = new int[26];
		for (int i = 0; i < n; i++) {
			freq[string.charAt(i) - 'a']++;
		}
		PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				return o2 - o1;
			}
		});
		for (int integer : freq) {
			if (integer != 0)
				priorityQueue.add(integer);
		}
		while (k-- > 0 && !priorityQueue.isEmpty()) {
			Integer tmp = priorityQueue.poll();
			tmp--;
			if (tmp > 0) {
				priorityQueue.add(tmp);
			}
		}
		int res = 0;
		while (!priorityQueue.isEmpty()) {
			Integer tmp = priorityQueue.poll();
			res += tmp * tmp;
		}
		System.out.println(res);
	}

}
